package vip.xiaonuo.task;


import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import vip.xiaonuo.core.timer.TimerTaskRunner;
import vip.xiaonuo.modular.attendancegroup.entity.AttendanceGroup;
import vip.xiaonuo.modular.attendancegroup.service.AttendanceGroupService;
import vip.xiaonuo.modular.attendancerecord.service.AttendancePlanService_OneDay;

import javax.annotation.Resource;
import java.util.List;

@Component
@Slf4j
public class AttendancePlanTask implements TimerTaskRunner {

    @Resource
    private AttendanceGroupService groupService;

    @Resource
    private AttendancePlanService_OneDay planService;

    @Override
    public void action(String jobParams, String taskId) {
        log.info("进入生成考勤计划定时任务");
        this.createPlan();
    }

    @Override
    @XxlJob("AttendancePlanTask")
    public void executeXxlJob() throws InterruptedException {
        log.info("进入生成考勤计划定时任务");
        this.createPlan();
    }

    private void createPlan() {
        List<AttendanceGroup> groups = groupService.list();
        for(AttendanceGroup group : groups){
            try{
                planService.createPlan(group);
            }catch (Exception e){
                e.printStackTrace();
            }

        }
    }
}
